<div id="withdrawApplyCreate<?php echo $uniqid;?>" style="padding-top: 20px">
    <el-form :model="params" method="post" size="small" label-width="140px" @submit.native.prevent label-position="right">
        <el-form-item label="提现金额：">
            <el-input-number v-model="params.money" :precision="2" :min="0" label="提现金额" size="large"></el-input-number>
        </el-form-item>
        <el-form-item label="提现方式：">
            <el-select v-model="params.bank_type" @change="bankTypeChang" style="max-width: 140px;" placeholder="请选择提现方式" popper-class="zindex_popper">
                <el-option
                        v-for="item in bank_type"
                        :key="item.type"
                        :label="item.name"
                        :value="item.type">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="提现帐号：" v-if="params.bank_type">
            <p v-if="back_account.id">{{back_account.name}} <span class="my_bank_btn" @click="changeBank">去修改</span></p>
            <p v-else>暂无提现帐号 <span class="my_bank_btn" @click="changeBank">去添加</span></p>
        </el-form-item>
        <el-form-item label="支付密码：">
            <el-input placeholder="请输入支付密码" v-model="params.pay_password" show-password size="small" style="max-width: 200px"></el-input>
        </el-form-item>
    </el-form>
    <div id="withdrawApplyCreatedlg" class="easyui-dialog" style="width:700px; height:580px;" title="信息框" closed="true"></div>
</div>
<script>
    var withdrawApplyCreateVm = new Vue({
        el: '#withdrawApplyCreate<?php echo $uniqid;?>',
        data: {
            params: {
                'money':0.00,
                'bank_id':0,
                'pay_password':'',
                'bank_type':'',
            },
            bank_type: JSON.parse('<?php echo addslashes($bank_type);?>'),
            back_account:{
                'id':0,
                'name':'',
            },
        },
        mounted(){
            this.init();
        },
        methods: {
            init(){
            },
            bankTypeChang:function (value) {
                let that = this;
                $.post('/merchant/bank/detail', {type:value}, function(res){
                    if(res.ret===0){
                        that.params.bank_id= res.data.id;
                        that.back_account.id = res.data.id;
                        let card_no = res.data.card_no;
                        if('undefined' !== typeof res.data.bank_name){
                            card_no = res.data.bank_name + '-' + card_no;
                        }
                        that.back_account.name = `${card_no} (${res.data.real_name})`;
                    }else{
                        that.params.bank_id= 0;
                        that.back_account.id = 0;
                        that.back_account.name = '';
                        $.messager.alert('提示',res.msg,'warning');
                    }
                });
            },
            changeBank:function (){
                $("#MerchantCapitalDlg").dialog('close');
                addTab('提现帐号','/merchant/bank/mybank');
            },
            submit: function(){
                let that = this;
                if( that.params.money <= 0){
                    $.messager.alert('提示', '请输入提现金额','warning');
                    return;
                }
                if('object' === typeof capitalInfoVm && parseFloat(capitalInfoVm.merchantCapitalDetail.money.replace(/[^\d\.-]/g, "")) < that.params.money){
                    $.messager.alert('提示', '提现金额不能超过可提现金额','warning');
                    return;
                }
                if( that.params.pay_password.length < 2){
                    $.messager.alert('提示', '请输入您的支付密码','warning');
                    return;
                }
                if( that.params.bank_type.length < 2){
                    $.messager.alert('提示', '请选择提现方式','warning');
                    return;
                }
                if( that.params.bank_id.length < 1){
                    $.messager.alert('提示', '请去添加提现帐号','warning');
                    return;
                }
                $.post('/merchant/withdraw/apply', that.params, function(res){
                    if(res.ret===0){
                        $.messager.show({
                            title:'提示',
                            msg:res.msg,
                            timeout:3000,
                            showType:'slide'
                        });
                        $('#<?php echo $uniqid;?>').form('clear');
                        $("#MerchantCapitalDlg").dialog('close');
                        if('object' === typeof capitalInfoVm){
                            let money_no_thousands_separator = capitalInfoVm.merchantCapitalDetail.money.split(",");
                            let new_money = parseFloat(money_no_thousands_separator.join("")) - that.params.money;
                            new_money = new_money.toFixed(2)+"";//保留两位小数
                            let withdraw_money_freeze_no_thousands_separator = capitalInfoVm.merchantCapitalDetail.withdraw_money_freeze.split(",");
                            let new_withdraw_money_freeze = parseFloat(withdraw_money_freeze_no_thousands_separator.join("")) + that.params.money;
                            new_withdraw_money_freeze = new_withdraw_money_freeze.toFixed(2)+"";//保留两位小数
                            capitalInfoVm.merchantCapitalDetail.money = new_money.replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,');
                            capitalInfoVm.merchantCapitalDetail.withdraw_money_freeze = new_withdraw_money_freeze.replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,');
                        }
                    }else{
                        $.messager.alert('提示',res.msg,'warning');
                    }
                });
            }
        }
    });
    $('#applyWithdrawSubmit').click(function(data){
        withdrawApplyCreateVm.submit();
    })
</script>
<style>
    .zindex_popper{
        z-index: 20000 !important;
    }

    .my_bank_btn{
        display: inline-block;
        cursor: pointer;
        line-height: 1;
        margin-left: 50px;
        border: 1px solid #1791dc;
        background-color: #84cbf6;
        border-radius: 5px;
        color: #fcfcfc;
        padding: 5px 10px;
    }

    .my_bank_btn:hover{
        background-color: #cc3333;
        border-color: #cc3333;
    }
</style>